package processingHandling;

import codeanticode.gsvideo.GSMovie;

/**
 * Movie template PAppletWrapper implementation.
 * Sets up a movie to be used as data based off the abstract width, height, frame rate, and file name functions.
 * Reads the movie data into the image each draw call.
 * 
 * @author Dylan James
 *
 */
public abstract class MoviePAppletWrapper extends PAppletWrapper{
	int width, height, frameRate;
	String filename;
	GSMovie myMovie;

	@Override
	public void WrapperSetup() {
		this.Initialize();
		// Initialize the applet window
		size(width, height);
		background(0);
		// Load and play the video in a loop
		myMovie = new GSMovie(this, filename);
		frameRate(frameRate);
		myMovie.loop();

		this.Setup();
	}

	@Override
	public void WrapperDraw() {
		// Grab image from the webcam if possible
		if (myMovie.available()) {
			myMovie.read();
			image(myMovie, 0, 0);
		}
		
		

		this.Draw();
	}
	
	public abstract void Setup();
	public abstract void Draw();

	/**
	 * Calls the functions needed to initialize this data.
	 */
	private void Initialize()
	{
		this.width = this.getWidth();
		this.height = this.getHeight();
		this.frameRate = this.getFrameRate();
		this.filename = this.getFilename();
	}

	/**
	 * Abstract function to allow Width setup.
	 * Should return the desired value for the width of the movie window.
	 */
	public abstract int getWidth();
	/**
	 * Abstract function to allow Height setup.
	 * Should return the desired value for the height of the movie window.
	 */
	public abstract int getHeight();
	/**
	 * Abstract function to allow FrameRate setup.
	 * Should return the desired value for the frame rate of the movie.
	 */
	public abstract int getFrameRate();
	/**
	 * Abstract function to allow Filename setup.
	 * Should return the name of the file to be opened to be played.
	 */
	public abstract String getFilename();



}
